<?php
define ("XMLFILE" ,"/usr/local/apache2/htdocs/config.xml");
#define ("XMLFILE" ,"config.xml");

function OpenXmlFile($XmlFile)
{
	$Ret_Array = array();
	if ( !file_exists($XmlFile)) {
		return NULL;
	}
	$Ret_Array["doc"] = new DOMDocument();
	$Ret_Array["doc"]->formatOutput = true;
	$Ret_Array["doc"]->preserveWhiteSpace = false;
	$Ret_Array["doc"]->load($XmlFile);
	$Ret_Array["xpath"] = new Domxpath($Ret_Array["doc"]);
	return $Ret_Array;
}

function OpenXmlFileForWrite($XmlFile)
{
	return  OpenXmlFile($XmlFile);
}

function OpenXmlFileForRead($XmlFile)
{
	$Ret_Array = OpenXmlFile($XmlFile);
	$xpath = $Ret_Array["xpath"];

	return $xpath;
}


#$query_string = "/MINI/NETWORK/DNSS/DNS";
function GetNumberOfNode($query_string)
{
	$xpath = OpenXmlFileForRead(XMLFILE);
	$evaluate_string = 'count('.$query_string.')';
	$entries = $xpath->evaluate($evaluate_string);

	return $entries;
}
#print "Number:". GetNumberOfNode($query_string). "\n";

#$query_string = "/MINI/NETWORK/DNSS/DNS";
function GetAllNodeValue($query_string)
{
	$xpath = OpenXmlFileForRead(XMLFILE);
	$results = $xpath->query($query_string);
	# $results is list type.
	return $results;
}
#$results = GetAllNodeValue($query_string);
#foreach ($results as $result)
#{
#	print $result->nodeValue;
#}

?>

